package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.EduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class EduController {
    @Autowired
    EduService eduService;
//    完成根据查询订单状态为已支付（1002）总金额的数字翻牌器
    @RequestMapping("/findFan")
    public Object findFan(){
        List<Map> list = eduService.findFan();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("final"));
        return jsonObject;
    }
//19）完成根据各省份查询订单的总成交额的省份热力图（5分）
    @RequestMapping("/findFf")
    public Object findFf(){
        List<Map> list = eduService.findFf();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject dataObject = new JSONObject();
        JSONArray mapnArray = new JSONArray();
        for (Map map : list) {
            JSONObject mapObject = new JSONObject();
            mapObject.put("name",map.get("name"));
            mapObject.put("value",map.get("final"));
            mapnArray.add(mapObject);
        }
dataObject.put("mapData",mapnArray);
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
//    完成求出各试卷平均成绩大于60的柱状图（5分
    @RequestMapping("/fingBu")
    public Object fingBu(){
        List<Map> list = eduService.fingBu();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONArray dataArray = new JSONArray();
        for (Map map : list) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("paper"));
            dataObject.put("value",map.get("dyu"));
            dataArray.add(dataObject);
        }
        jsonObject.put("data",dataArray);
        return jsonObject;
    }
}
